var app = getApp();
Component({
    properties: {
        prize: Object,
        oid : String,
        params : Object,
    },
    data:{
        tab_zhuan:false,
        chouing : false,
        animationData : '',
        getedprize : {},
        showgift : 0,
        showprize : false,
    },
    options : {
        addGlobalClass : true,
    },
    methods: {
	    getLottery : function(prize,oid){
	        var self = this;
	        if( self.data.chouing ) return false;
	        self.setData({
	            tab_zhuan : false,
	            animationData : false,
	            chouing : true,
	            showprize : true,
	            prize : prize,
	        },function(){
		        self.data.animation = wx.createAnimation({
		            duration: 100*1000,
		        })
		        self.data.animation.rotate(360*100).step()
		        self.setData({
		            animationData: self.data.animation.export()
		        })
	        })

	        app.com.http('order','POST',{op:'getprize',oid:oid},0,true,'','',function(res){
	            if (!res.data.errno && res.data.errno !== undefined) {
	                
	                var isother = 0;
	                var otherindex = -1;
	                var isin = 0;
	                for (var i = 0; i < self.data.prize.allprize.length; i++) {
	                    if( self.data.prize.allprize[i].id == res.data.data.prizeid ){
	                        self.setData({
	                            tab_zhuan : i+1,
	                            getedprize : res.data.data.prize,
	                        });
	                        isin = 1;

	                        self.hidep();
	                    }
	                    if( self.data.prize.allprize[i].id == -1 ){
	                        isother = 1;
	                        otherindex = i;
	                    }
	                }

	                if( isother == 1 && isin == 0 ){
	                    self.setData({
	                        tab_zhuan : otherindex+1,
	                        getedprize : res.data.data.prize
	                    });
	                }
	                self.hidep();
	            }else if( res.data.errno == 2 ){
	            	self.hidep();
	            	self.data.chouing = false;
	            }else{
	                app.com.toast(res.data.message);
	                self.setData({
	                    showprize : false,
	                    tab_zhuan : false,
	                    showgift : 0,
	                });
	                self.data.chouing = false;
	            }
	        });
	    },
	    closeall : function(){
	        this.setData({
	            tab_zhuan : false,
	            showgift : 0,
	            showprize : false,
	            getedprize : false,
	        });
	        this.triggerEvent('paylott',this.data.getedprize);
	    },
	    navigateto(e){
	    	app.com.navigateto( e );
	    },
	    hidep(){
	    	var  self = this;
            setTimeout(function(){
                self.data.animationa = wx.createAnimation({
                    duration: 0,
                })
                self.data.animationa.rotate(0).step()
                self.setData({
                    animationData: self.data.animationa.export()
                })
                self.setData({
                    showgift : 1,
                });
                self.data.chouing = false;
            },3000)	    	
	    }
    }

})